home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_sys.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  8KB  |  264 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import unittest
  5. import test.test_support as test
  6. import sys
  7. import cStringIO
  8.  
  9. class SysModuleTest(unittest.TestCase):
  10.     
  11.     def test_original_displayhook(self):
  12.         import __builtin__ as __builtin__
  13.         savestdout = sys.stdout
  14.         out = cStringIO.StringIO()
  15.         sys.stdout = out
  16.         dh = sys.__displayhook__
  17.         self.assertRaises(TypeError, dh)
  18.         if hasattr(__builtin__, '_'):
  19.             del __builtin__._
  20.         
  21.         dh(None)
  22.         self.assertEqual(out.getvalue(), '')
  23.         self.assert_(not hasattr(__builtin__, '_'))
  24.         dh(42)
  25.         self.assertEqual(out.getvalue(), '42\n')
  26.         self.assertEqual(__builtin__._, 42)
  27.         del sys.stdout
  28.         self.assertRaises(RuntimeError, dh, 42)
  29.         sys.stdout = savestdout
  30.  
  31.     
  32.     def test_lost_displayhook(self):
  33.         olddisplayhook = sys.displayhook
  34.         del sys.displayhook
  35.         code = compile('42', '<string>', 'single')
  36.         self.assertRaises(RuntimeError, eval, code)
  37.         sys.displayhook = olddisplayhook
  38.  
  39.     
  40.     def test_custom_displayhook(self):
  41.         olddisplayhook = sys.displayhook
  42.         
  43.         def baddisplayhook(obj):
  44.             raise ValueError
  45.  
  46.         sys.displayhook = baddisplayhook
  47.         code = compile('42', '<string>', 'single')
  48.         self.assertRaises(ValueError, eval, code)
  49.         sys.displayhook = olddisplayhook
  50.  
  51.     
  52.     def test_original_excepthook(self):
  53.         savestderr = sys.stderr
  54.         err = cStringIO.StringIO()
  55.         sys.stderr = err
  56.         eh = sys.__excepthook__
  57.         self.assertRaises(TypeError, eh)
  58.         
  59.         try:
  60.             raise ValueError(42)
  61.         except ValueError:
  62.             exc = None
  63.             eh(*sys.exc_info())
  64.  
  65.         sys.stderr = savestderr
  66.         self.assert_(err.getvalue().endswith('ValueError: 42\n'))
  67.  
  68.     
  69.     def test_exc_clear(self):
  70.         self.assertRaises(TypeError, sys.exc_clear, 42)
  71.         
  72.         def clear_check(exc):
  73.             (typ, value, traceback) = sys.exc_info()
  74.             self.assert_(typ is not None)
  75.             self.assert_(value is exc)
  76.             self.assert_(traceback is not None)
  77.             sys.exc_clear()
  78.             (typ, value, traceback) = sys.exc_info()
  79.             self.assert_(typ is None)
  80.             self.assert_(value is None)
  81.             self.assert_(traceback is None)
  82.  
  83.         
  84.         def clear():
  85.             
  86.             try:
  87.                 raise ValueError, 42
  88.             except ValueError:
  89.                 exc = None
  90.                 clear_check(exc)
  91.  
  92.  
  93.         clear()
  94.         
  95.         try:
  96.             raise ValueError, 13
  97.         except ValueError:
  98.             exc = None
  99.             (typ1, value1, traceback1) = sys.exc_info()
  100.             clear()
  101.             (typ2, value2, traceback2) = sys.exc_info()
  102.             self.assert_(typ1 is typ2)
  103.             self.assert_(value1 is exc)
  104.             self.assert_(value1 is value2)
  105.             self.assert_(traceback1 is traceback2)
  106.  
  107.         clear_check(exc)
  108.  
  109.     
  110.     def test_exit(self):
  111.         self.assertRaises(TypeError, sys.exit, 42, 42)
  112.         
  113.         try:
  114.             sys.exit(0)
  115.         except SystemExit:
  116.             exc = None
  117.             self.assertEquals(exc.code, 0)
  118.         except:
  119.             self.fail('wrong exception')
  120.  
  121.         self.fail('no exception')
  122.         
  123.         try:
  124.             sys.exit(42)
  125.         except SystemExit:
  126.             exc = None
  127.             self.assertEquals(exc.code, 42)
  128.         except:
  129.             self.fail('wrong exception')
  130.  
  131.         self.fail('no exception')
  132.         
  133.         try:
  134.             sys.exit((42,))
  135.         except SystemExit:
  136.             exc = None
  137.             self.assertEquals(exc.code, 42)
  138.         except:
  139.             self.fail('wrong exception')
  140.  
  141.         self.fail('no exception')
  142.         
  143.         try:
  144.             sys.exit('exit')
  145.         except SystemExit:
  146.             exc = None
  147.             self.assertEquals(exc.code, 'exit')
  148.         except:
  149.             self.fail('wrong exception')
  150.  
  151.         self.fail('no exception')
  152.         
  153.         try:
  154.             sys.exit((17, 23))
  155.         except SystemExit:
  156.             exc = None
  157.             self.assertEquals(exc.code, (17, 23))
  158.         except:
  159.             self.fail('wrong exception')
  160.  
  161.         self.fail('no exception')
  162.  
  163.     
  164.     def test_getdefaultencoding(self):
  165.         if test.test_support.have_unicode:
  166.             self.assertRaises(TypeError, sys.getdefaultencoding, 42)
  167.             self.assert_(isinstance(sys.getdefaultencoding(), str))
  168.         
  169.  
  170.     
  171.     def test_setcheckinterval(self):
  172.         self.assertRaises(TypeError, sys.setcheckinterval)
  173.         orig = sys.getcheckinterval()
  174.         for n in (0, 100, 120, orig):
  175.             sys.setcheckinterval(n)
  176.             self.assertEquals(sys.getcheckinterval(), n)
  177.         
  178.  
  179.     
  180.     def test_recursionlimit(self):
  181.         self.assertRaises(TypeError, sys.getrecursionlimit, 42)
  182.         oldlimit = sys.getrecursionlimit()
  183.         self.assertRaises(TypeError, sys.setrecursionlimit)
  184.         self.assertRaises(ValueError, sys.setrecursionlimit, -42)
  185.         sys.setrecursionlimit(10000)
  186.         self.assertEqual(sys.getrecursionlimit(), 10000)
  187.         sys.setrecursionlimit(oldlimit)
  188.  
  189.     
  190.     def test_getwindowsversion(self):
  191.         if hasattr(sys, 'getwindowsversion'):
  192.             v = sys.getwindowsversion()
  193.             self.assert_(isinstance(v, tuple))
  194.             self.assertEqual(len(v), 5)
  195.             self.assert_(isinstance(v[0], int))
  196.             self.assert_(isinstance(v[1], int))
  197.             self.assert_(isinstance(v[2], int))
  198.             self.assert_(isinstance(v[3], int))
  199.             self.assert_(isinstance(v[4], str))
  200.         
  201.  
  202.     
  203.     def test_dlopenflags(self):
  204.         if hasattr(sys, 'setdlopenflags'):
  205.             self.assert_(hasattr(sys, 'getdlopenflags'))
  206.             self.assertRaises(TypeError, sys.getdlopenflags, 42)
  207.             oldflags = sys.getdlopenflags()
  208.             self.assertRaises(TypeError, sys.setdlopenflags)
  209.             sys.setdlopenflags(oldflags + 1)
  210.             self.assertEqual(sys.getdlopenflags(), oldflags + 1)
  211.             sys.setdlopenflags(oldflags)
  212.         
  213.  
  214.     
  215.     def test_refcount(self):
  216.         self.assertRaises(TypeError, sys.getrefcount)
  217.         c = sys.getrefcount(None)
  218.         n = None
  219.         self.assertEqual(sys.getrefcount(None), c + 1)
  220.         del n
  221.         self.assertEqual(sys.getrefcount(None), c)
  222.         if hasattr(sys, 'gettotalrefcount'):
  223.             self.assert_(isinstance(sys.gettotalrefcount(), int))
  224.         
  225.  
  226.     
  227.     def test_getframe(self):
  228.         self.assertRaises(TypeError, sys._getframe, 42, 42)
  229.         self.assertRaises(ValueError, sys._getframe, 2000000000)
  230.         self.assert_(SysModuleTest.test_getframe.im_func.func_code is sys._getframe().f_code)
  231.  
  232.     
  233.     def test_attributes(self):
  234.         self.assert_(isinstance(sys.api_version, int))
  235.         self.assert_(isinstance(sys.argv, list))
  236.         self.assert_(sys.byteorder in ('little', 'big'))
  237.         self.assert_(isinstance(sys.builtin_module_names, tuple))
  238.         self.assert_(isinstance(sys.copyright, basestring))
  239.         self.assert_(isinstance(sys.exec_prefix, basestring))
  240.         self.assert_(isinstance(sys.executable, basestring))
  241.         self.assert_(isinstance(sys.hexversion, int))
  242.         self.assert_(isinstance(sys.maxint, int))
  243.         self.assert_(isinstance(sys.maxunicode, int))
  244.         self.assert_(isinstance(sys.platform, basestring))
  245.         self.assert_(isinstance(sys.prefix, basestring))
  246.         self.assert_(isinstance(sys.version, basestring))
  247.         vi = sys.version_info
  248.         self.assert_(isinstance(vi, tuple))
  249.         self.assertEqual(len(vi), 5)
  250.         self.assert_(isinstance(vi[0], int))
  251.         self.assert_(isinstance(vi[1], int))
  252.         self.assert_(isinstance(vi[2], int))
  253.         self.assert_(vi[3] in ('alpha', 'beta', 'candidate', 'final'))
  254.         self.assert_(isinstance(vi[4], int))
  255.  
  256.  
  257.  
  258. def test_main():
  259.     test.test_support.run_unittest(SysModuleTest)
  260.  
  261. if __name__ == '__main__':
  262.     test_main()
  263.  
  264.